package view_X_O;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: User
 * Date: 09.07.14
 * Time: 19:40
 * To change this template use File | Settings | File Templates.
 */
public class FrameXO implements Runnable {
    private JFrame frame;
    private static final int BUTTSIZE = 20;
    private FrameCub frameCub;
    private String path;
    private ImageIcon icon;


    @Override
    public void run() {
//        frameCub = new FrameCub();
//        if(frameCub.getFlag()==1){
            path = "D:\\JAVA_PSI\\JAVA_project\\hbntPlayer\\x_o\\src\\main\\resources\\img\\button\\x.png";
//        }
//        if (frameCub.getFlag()==0){
//            path="D:\\JAVA_PSI\\JAVA_project\\hbntPlayer\\x_o\\src\\main\\resources\\img\\button\\o.png";
//        }
        icon  = new ImageIcon(path);
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension scrin = kit.getScreenSize();
        frame = new JFrame("крестики-нолики");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(scrin.height / 2, scrin.height / 2);
        frame.setLocation(scrin.width / 4, scrin.height / 4);
        frame.setResizable(false);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(3, 3));


        final JButton b1 = new JButton();
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b1.setIcon(icon);
            }
        });

        final JButton b2 = new JButton();
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b2.setIcon(icon);
            }
        });
        final JButton b3 = new JButton();
        b3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b3.setIcon(icon);
            }
        });
        final JButton b4 = new JButton();
        b4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b4.setIcon(icon);
            }
        });
        final JButton b5 = new JButton();
        b5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b5.setIcon(icon);
            }
        });
        final JButton b6 = new JButton();
        b6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b6.setIcon(icon);
            }
        });
        final JButton b7 = new JButton();
        b7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b7.setIcon(icon);
            }
        });
        final JButton b8 = new JButton();
        b8.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b8.setIcon(icon);

            }
        });
        final JButton b9 = new JButton();
        b9.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                b9.setIcon(icon);
            }
        });


        panel.add(b1);
        panel.add(b2);
        panel.add(b3);
        panel.add(b4);
        panel.add(b5);
        panel.add(b6);
        panel.add(b7);
        panel.add(b8);
        panel.add(b9);

        frame.add(panel);
        frame.setVisible(true);
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
